package com.four.bmm.controller;

import com.four.bmm.entity.Admin;
import com.four.bmm.entity.User;
import com.four.bmm.service.AdminService;
import com.four.bmm.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/RegAdminServlet")
public class RegAdminServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String adminname = request.getParameter("adminname");
        String adminpwd = request.getParameter("adminname");
        Admin admin = new Admin(adminname, adminpwd);
        AdminService adminService = new AdminService();
        boolean flag = adminService.registerAdmin(admin);
        if (flag) {
            request.getRequestDispatcher("back/login.jsp").forward(request, response);
        } else {
            response.sendRedirect("welcome.html");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
